package com.ccb.cloud.rca.appservice.aopTest;

import com.ccb.cloud.rca.appservice.dao.DO.assetsupervise.User;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

@Aspect
@Component
public class aopTest {

    @Pointcut(value = "@annotation(com.ccb.cloud.rca.appservice.aopTest.MyAop)")
    public Object annotationsAspect(){
        return null;
    }

    @Around("annotationsAspect()")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable{
        System.out.println("执行方法之前");
        MethodSignature signature = (MethodSignature)pjp.getSignature();
        System.out.println("方法名===="+signature.getName());
        Method method = signature.getMethod();
        Object[] args = pjp.getArgs();
        Field name = args[0].getClass().getDeclaredField("name");
        name.setAccessible(true);
        name.set(args[0],"hahah");
        Object proceed = pjp.proceed(args);
        System.out.println("执行方法之后");
        return proceed;
    }
}
